local fk__guici = fk.CreateSkill {

  name = "fk__guici",

  tags = { Skill.Compulsory, Skill.Switch },

}

local U = require "packages/utility/utility"


fk__guici:addEffect(fk.RoundStart, {

  anim_type = "switch",

  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(fk__guici.name)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local patternTable = {}
    if player:getSwitchSkillState(fk__guici.name, true) == fk.SwitchYang then
      patternTable = { ["heart"] = {}, ["diamond"] = {}, ["spade"] = {}, ["club"] = {} }
      for _, id in ipairs(room.draw_pile) do
        local pattern = Fk:getCardById(id):getSuitString()
        if patternTable[pattern] then
          table.insert(patternTable[pattern], id)
        end
      end
    else
      patternTable = { ["basic"] = {}, ["trick"] = {}, ["equip"] = {} }
      for _, id in ipairs(room.draw_pile) do
        local pattern = Fk:getCardById(id):getTypeString()
        if patternTable[pattern] then
          table.insert(patternTable[pattern], id)
        end
      end
    end
    local get = {}
    for _, ids in pairs(patternTable) do
      if #ids > 0 then
        table.insert(get, table.random(ids))
      end
    end
    if #get > 0 then
      room:obtainCard(player, get, false, fk.ReasonPrey, player.id, fk__guici.name, "@@fk__guici-inhand")
    end
  end,
})

return fk__guici